/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.mrp.ppm.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

/**
 *
 * @author Zhu Xin nd Zhang Ying
 */
@Entity
public class IndivDMPS implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    // to indicate which product, 0- A, 1-B, 2-C, 3-D
    private int productIndex;
    
    @OrderBy("dayIndex")
    @OneToMany(targetEntity=DailyPlannedProduction.class, cascade={CascadeType.ALL}, fetch= FetchType.EAGER)
    private List<DailyPlannedProduction> dailyDemandList = new ArrayList<DailyPlannedProduction>();

    public IndivDMPS() {
        for (int i = 0 ; i < 5; i++){
            DailyPlannedProduction dpp = new DailyPlannedProduction(i);
            dailyDemandList.add(dpp);
        }
    }
    
    public DailyPlannedProduction returnDailyPlannedProduction(Integer i){
        // 0 -> Mon, .. 4->Fri
        return dailyDemandList.get(i);
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<DailyPlannedProduction> getDailyDemandList() {
        return dailyDemandList;
    }

    public void setDailyDemandList(List<DailyPlannedProduction> dailyDemandList) {
        this.dailyDemandList = dailyDemandList;
    }

    public int getProductIndex() {
        return productIndex;
    }

    public void setProductIndex(int productIndex) {
        this.productIndex = productIndex;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {

        if (!(object instanceof IndivDMPS)) {
            return false;
        }
        IndivDMPS other = (IndivDMPS) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.mrp.ppm.entity.IndivDMPS[ id=" + id + " ]";
    }
    
}
